package com.yulan.fastkillcourse.service;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yulan.fastkillcourse.common.Const;
import com.yulan.fastkillcourse.model.Course;
import com.yulan.fastkillcourse.model.CourseMargin;
import com.yulan.fastkillcourse.model.CourseOrder;
import com.yulan.fastkillcourse.redis.RedisService;
import com.yulan.fastkillcourse.redis.key.CourseKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class FastkillService {

    @Autowired
    CourseOrderService courseOrderService;

    @Autowired
    CourseMarginService courseMarginService;

    @Autowired
    RedisService redisService;

    @Transactional
    public boolean DoFastKill(int uid,int cid){
        CourseOrder courseOrder = CourseOrder.builder()
                .uid(uid)
                .cid(cid)
                .build();

        boolean success1 = courseOrderService.save(courseOrder);
        if(success1) redisService.set(CourseKey.getCourseOrder,""+uid,cid, Const.RedisCacheExtime.COURSE_LIST);
        boolean success2 = courseMarginService.reduceMargin(cid);

        return success1&&success2;
    }

}
